package com.example.dingdong.daomain;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

import javax.persistence.CascadeType;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.ManyToMany;
import javax.persistence.OneToMany;
import javax.persistence.Table;

import com.alibaba.fastjson.annotation.JSONField;


/**
 * @ClassName:  RoleEntity
 * @Description:角色实体
 * @Author chengwenxing
 * @DateTime 2021-03-31 
 */
@Entity
@Table(name ="role_entity")
public class RoleEntity implements Serializable {

	private static final long serialVersionUID = 1L;

	/**
	 * 数据库自增长ID
	 */
	@Id
	@GeneratedValue(strategy = GenerationType.IDENTITY)
	private int id;

	/**
	 * 路由-角色（多对多）
	 */
	@JSONField(serialize = false)
	@ManyToMany(mappedBy = "joinRoleList", cascade = CascadeType.ALL, fetch = FetchType.LAZY)
	private List<RouterEntity> routerList = new ArrayList<>();

	/**
	 * 角色-基本人员（一对多）
	 */
	@JSONField(serialize = false)
	@ManyToMany(cascade = CascadeType.ALL, fetch = FetchType.LAZY)
	@JoinTable(name = "role_relate_basicuser", joinColumns = @JoinColumn(name = "role_id"), inverseJoinColumns = @JoinColumn(name = "basicuser_id"))
	private List<BasicUserEntity> joinBasicUserList = new ArrayList<>();
	
	/**
	 * 角色名称
	 */
	private String roleName;

	/**
	 * 角色备注
	 */
	private String remark;

	/**
	 * 删除标识
	 */
	@JSONField(serialize = false)
	private boolean delFlag = true;

	/*
	 * 构造器
	 */
	public RoleEntity() {

	}

	public RoleEntity(String roleName, String remark) {
		this.roleName = roleName;
		this.remark = remark;
	}

	public int getId() {
		return id;
	}

	public void setId(int id) {
		this.id = id;
	}

	public List<RouterEntity> getRouterList() {
		return routerList;
	}

	public void setRouterList(List<RouterEntity> routerList) {
		this.routerList = routerList;
	}

	public List<BasicUserEntity> getJoinBasicUserList() {
		return joinBasicUserList;
	}

	public void setJoinBasicUserList(List<BasicUserEntity> joinBasicUserList) {
		this.joinBasicUserList = joinBasicUserList;
	}

	public String getRoleName() {
		return roleName;
	}

	public void setRoleName(String roleName) {
		this.roleName = roleName;
	}

	public String getRemark() {
		return remark;
	}

	public void setRemark(String remark) {
		this.remark = remark;
	}

	public boolean isDelFlag() {
		return delFlag;
	}

	public void setDelFlag(boolean delFlag) {
		this.delFlag = delFlag;
	}

	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result + (delFlag ? 1231 : 1237);
		result = prime * result + id;
		result = prime * result + ((joinBasicUserList == null) ? 0 : joinBasicUserList.hashCode());
		result = prime * result + ((remark == null) ? 0 : remark.hashCode());
		result = prime * result + ((roleName == null) ? 0 : roleName.hashCode());
		result = prime * result + ((routerList == null) ? 0 : routerList.hashCode());
		return result;
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		RoleEntity other = (RoleEntity) obj;
		if (delFlag != other.delFlag)
			return false;
		if (id != other.id)
			return false;
		if (joinBasicUserList == null) {
			if (other.joinBasicUserList != null)
				return false;
		} else if (!joinBasicUserList.equals(other.joinBasicUserList))
			return false;
		if (remark == null) {
			if (other.remark != null)
				return false;
		} else if (!remark.equals(other.remark))
			return false;
		if (roleName == null) {
			if (other.roleName != null)
				return false;
		} else if (!roleName.equals(other.roleName))
			return false;
		if (routerList == null) {
			if (other.routerList != null)
				return false;
		} else if (!routerList.equals(other.routerList))
			return false;
		return true;
	}
	
}
